package scene;

import game.Consts;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class RenderInfo {
	private BufferedImage image;
	public int width;
	public int height;
	public Color bgCol = new Color(0,0,0);

	public RenderInfo() {
		image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
		width = 800;
		height = 600;
		bgCol = new Color(0,0,0);
	}

	public RenderInfo(String background, int width, int height) {
		this.width = width;
		this.height = height;

		image = new BufferedImage(Consts.SCR_W, Consts.SCR_H, BufferedImage.TYPE_INT_RGB);
		try {
			BufferedImage tmp = ImageIO.read(new File(background));
			image.getGraphics().drawImage(tmp, 0, 0, Consts.SCR_W, Consts.SCR_H, 0, 0, tmp.getWidth(), tmp.getHeight(), null);
		} catch (Exception e) {
		}
	}

	public Color getBackgroundPixel(int x, int y, int w, int h) {
		if (image == null) {
			return bgCol;
		}
		float u = (float) x / w * image.getWidth();
		float v = (float) y / h * image.getHeight();
		int[] result = new int[3];
		result = image.getRaster().getPixel((int) u, (int) v, result);
		return new Color(result);
	}

	public float aspectRatio() {
		return (float) width / (float) height;
	}

	@Override
	public String toString() {
		return "" + width + " x " + height + " (bg: " + image + " or " + bgCol + ")";
	}

	public Image getBackgroundImage() {
		return this.image;
	}
}
